//
//  SSGoodsListCollectionView.m
//  textDemo
//
//  Created by Esther on 2017/2/21.
//  Copyright © 2017年 Esther. All rights reserved.
//

#import "SSGoodsListCollectionView.h"
#import "SSGoodsListCell.h"

@interface SSGoodsListCollectionView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic, strong) NSArray <SSPromotion *> *promotionLists;
@end
@implementation SSGoodsListCollectionView
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        [self registerClass:[SSGoodsListCell class] forCellWithReuseIdentifier:@"GoodsListCell"];
        
        self.delegate = self;
        self.dataSource = self;
        
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
}

#pragma mark -
#pragma mark - delegate && datasource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SSGoodsListCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GoodsListCell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor ss_randomColor];
    cell.promotion = self.promotionList[indexPath.item];
//    NSLog(@"%@",self.promotionLists);
//    NSLog(@"%@",self.promotionList);
    
   
    
    
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    NSLog(@"%@",self.promotionList);
    if (self.promotionBlock) {
        self.promotionBlock(indexPath.item);
    }
    
}


#pragma mark -
#pragma mark - set
- (void)setPromotionList:(NSArray<SSPromotion *> *)promotionList{
    _promotionList = promotionList;
    
    [self reloadData];
    
    
}



@end
